# Maintainer: Cameron Banta <cbanta@gmail.com>
pkgname=pgcluster
pkgver=1.9.00001
_myver=1.9.0rc5
pkgrel=0
pkgdesc="PostgreSQL with multi-master cluster/replication patch"
url="http://pgfoundry.org/projects/pgcluster/"
arch="all !aarch64"
license="BSD"
depends=
makedepends="readline-dev libressl-dev zlib-dev"
subpackages="$pkgname-dev $pkgname-doc $pkgname-libpq $pkgname-client"
source="http://pgfoundry.org/frs/download.php/1705/$pkgname-$_myver.tar.gz
	musl-fixes.patch
	$pkgname.initd
	$pkgname.confd
	"

[ "$ALPINE_LIBC" = "eglibc" ] && arch=

_builddir="$srcdir/$pkgname-$_myver"

prepare() {
	cd "$_builddir"
	update_config_sub || return 1
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done
}

build() {
	cd "$_builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--mandir=/usr/share/man \
		--with-docdir=/usr/share/doc \
		--with-openssl \
		|| return 1

	make || return 1
}

package() {
	cd "$_builddir"
	make DESTDIR="$pkgdir" install || return 1

	install -D -m755 "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -D -m644 "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname || return 1
}

libpq() {
	depends=
	pkgdesc="PGCluster libraries"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libpq.so* "$subpkgdir"/usr/lib/
}

client() {
	depends=
	pkgdesc="PGCluster client"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/psql "$subpkgdir"/usr/bin/
}


sha512sums="825b3da733c2e455bbdfca5833ec6f874d622529cc70fa6a398db458696d8398aa52101633ea703c698df0c86170b2522bb289ac3888b3f76575781f4a4c0d64  pgcluster-1.9.0rc5.tar.gz
e07a310644f6bad61a199c0d16997d2cd5105a81ad92074839c8296f7357e0abd25a17601485f6baf5b62a07e478fda1ceb36ef79dff2341f5b5ea912bd5b17e  musl-fixes.patch
32f21e761e963f91bd248f52ecb3c2abb9f0951fd5fb6b29c682ef2825aae2ed37483da728dfb8ce6281305e75568a1eac5037ced04ead604ce1c800695a1b52  pgcluster.initd
2dfa32a7c5fb39bf0fcc91f49a8fa432a983ad7eeecffe969f030e60da6ad5502aba6160daaae19c30c8596aab0ecf246775a53a18acb841c73c409a5a959bb2  pgcluster.confd"
